<?php

class FraisForfaitController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        $lesFraisForfaits = new Application_Model_DbTable_FraisForfait();
        $this->view->lesFraisForfaits = $lesFraisForfaits->fetchAll();
    }

    public function listerAction()
    {
        $lesFraisForfaits = new Application_Model_DbTable_FraisForfait();
        $this->view->lesFraisForfaits = $lesFraisForfaits->fetchAll();
    }

    public function modifierAction()
    {
        $form = new Application_Form_Fraisforfait();
        $form->envoyer->setLabel('Sauvegarder');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            $formData = $this->getRequest()->getPost();
            if ($form->isValid($formData)) {
                $id = $form->getValue('id');
                $montant = $form->getValue('montant');
                $lesFraisForfaits = new Application_Model_DbTable_FraisForfait();
                $lesFraisForfaits->modifierFraisForfait($id, $montant);
                $this->_helper->redirector('index');
            } else {
                $form->populate($formData);
            }
        } else {
            $id = $this->_getParam('id', 0); // attention, valeur 0 invalide
            $lesFraisForfaits = new Application_Model_DbTable_FraisForfait();
            $form->populate($lesFraisForfaits->obtenirFraisForfait($id));
        }
    }

    public function modifierVueAction()
    {
        $lesFraisForfaits = new Application_Model_DbTable_FraisForfait();
        $this->view->lesFraisForfaits = $lesFraisForfaits->fetchAll();
    }


}



